package com.ax.api.route.base.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.ax.api.route.util.RouteConfig;

@RestController
@RequestMapping("/system")
public class SystemRoute {
	 @Autowired
	 LoadBalancerClient loadBalancerClient;
	 @Autowired
	 RestTemplate restTemplate;
	 
	@GetMapping("/systemconsumer")
	public String consumer() {
	    ServiceInstance serviceInstance = loadBalancerClient.choose(RouteConfig.BASE_ROUTE);
	    String url = "http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + "/**";
	    return restTemplate.getForObject(url, String.class);
}
}
